﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRM.DAL.DAO;
using HRM.DAL.Gateway;

namespace HRM.BLL
{
    public class UserManager
    {
        UserGateway gateway = new UserGateway();
        public string CreateNewUser(User user)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(user.Employee.EmpCode);
            if (gateway.HasThisUserAlreadyExsit(empId,user))
            {
                return "An account already exist by using Employee Code or User Name";
            }
            else
            {
                return gateway.CreateNewUser(user, empId);
            }
        }

        public bool ChangePassword(User user)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(user.Employee.EmpCode);
            return gateway.ChangePassword(user, empId);
        }
        public bool ChangeUsernamePassword(User user)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(user.Employee.EmpCode);
            return gateway.ChangeUsernamePassword(user, empId);
        }

        public bool ResetAccounts(Code code)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(code);
            return gateway.ResetAccounts(empId);
        }

        public bool DeleteAccount(Code code)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(code);
            return gateway.ResetAccounts(empId);
        }

        public User CheckAuthentication(User user)
        {
            return gateway.CheckAuthentication(user);
        }

        public bool EditAccount(User user)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(user.Employee.EmpCode);
            return gateway.EditAccount(user, empId);
        }

        public User GetAccountsDetails(User user)
        {
            EmployeeManager employeeManager = new EmployeeManager();
            int empId = employeeManager.GetEmployeeID(user.Employee.EmpCode);
            return gateway.GetAccountsDetails(empId);
        }

    }
}